USE [shop_v3]
GO

/****** Object:  StoredProcedure [dbo].[ps_afflivres]    Script Date: 12/19/2012 14:27:04 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[ps_afflivres] @deb INT, @ligpage INT
AS
BEGIN
SET NOCOUNT ON
SELECT A.LIV_ID, LIV_ISBN, LIV_TITRE, LIV_SOUSTITRE, LIV_PRIXHT, LIV_RESUME, LIV_DATEPUBLICATION, LIV_NBPAGES, AUT_NOM, AUT_PRENOM, LIV_STOCK, TVA_TAUX, EDI_NOM, GEN_LABEL, EVE_LABEL
FROM (
SELECT L.LIV_ID, LIV_ISBN, LIV_TITRE, LIV_SOUSTITRE, LIV_PRIXHT, LIV_RESUME, LIV_DATEPUBLICATION, LIV_NBPAGES, LIV_STOCK, TVA_TAUX, EDI_NOM, GEN_LABEL, EVE_LABEL, AU.AUT_NOM, AU.AUT_PRENOM, row_number() OVER (ORDER BY L.LIV_ID) AS rownum
FROM T_LIVRES L INNER JOIN T_TVA T
ON L.TVA_ID = T.TVA_ID
INNER JOIN T_EDITEURS E
ON L.EDI_ID = E.EDI_ID
INNER JOIN T_GENRES G
ON L.GEN_ID = G.GEN_ID
LEFT OUTER JOIN T_EVENTS EV
ON L.EVE_ID = EV.EVE_ID
LEFT OUTER JOIN TJ_AUTEURS_AUT AA
ON L.LIV_ID = AA.LIV_ID
LEFT OUTER JOIN T_AUTEURS AU
ON AA.AUT_ID = AU.AUT_ID) AS A
WHERE A.rownum BETWEEN (@deb+1) AND (@deb + @ligpage)
END


GO


